package com.wxy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wxy.client.userClient;

import io.github.resilience4j.bulkhead.annotation.Bulkhead;
import io.github.resilience4j.ratelimiter.annotation.RateLimiter;

@RestController
@RequestMapping("/bulkheadsc02")
public class BulkheadController {
	@Autowired
	private userClient userClient;
	@RequestMapping("/ratelimiter/{id}")
    @RateLimiter(name = "userservice",fallbackMethod = "myBulkheadFallback")
	public String ratelimiter(@PathVariable("id") int id) {
		return userClient.getMessage(id);
	}
	@RequestMapping("/bulkhead/{id}")
    @Bulkhead(name = "userservice",fallbackMethod = "myBulkheadFallback",type = Bulkhead.Type.THREADPOOL)
	public String bulkhead(@PathVariable("id") int id) {
		return userClient.getMessage(id);
	}
	public String myBulkheadFallback(int id,Throwable t) {
		return "myBulkheadFallback，隔板超出最大数量限制，系统繁忙，请稍后再试-----/(ㄒoㄒ)/~~";
	}
}
